﻿using System.ComponentModel.Composition;

namespace GaleSong
{
    /// <summary>
    ///     Base <see cref="IPage" /> class for various implementations of <see cref="IPage" />.
    /// </summary>
    public abstract class PageBase : LocalizableDisplay, IPage
    {
        private string _icon;
        private bool _isSelected;
        private ViewStrategy _viewStrategy;
        protected bool showFlyoutButton = false;

        protected PageBase()
            : this(null)
        {
        }

        protected PageBase(string name)
        {
            Name = name ?? GetType().Name.Replace("Page", string.Empty);
            AutoUpdate = true;
        }

        public string Icon
        {
            get { return _icon; }
            set
            {
                _icon = value;
                NotifyPropertyChanged(() => Icon);
            }
        }

        public virtual bool ShowFlyoutButton
        {
            get { return showFlyoutButton; }
            set
            {
                showFlyoutButton = value;
                NotifyPropertyChanged(() => ShowFlyoutButton);
            }
        }

        public virtual bool IsSelected
        {
            get { return _isSelected; }
            set
            {
                _isSelected = value;
                NotifyPropertyChanged(() => IsSelected);
            }
        }

        public virtual object Content
        {
            get { return ViewHelper.CreateView(this); }
        }

        public virtual bool Cacheable
        {
            get { return true; }
        }

        public ViewStrategy ViewStrategy
        {
            get { return _viewStrategy; }
            set
            {
                _viewStrategy = value;
                NotifyPropertyChanged(() => ViewStrategy, () => Content);
            }
        }

        [Import(typeof(IWorkbench))]
        public IWorkbench Workbench { get; set; }

        public virtual void Initialize()
        {
        }
    }
}